<template>
  <div class="dashboard-container">
    <div class="filter-container">
      <el-row :gutter="10" style="width:100%">
        <el-col :span="3">
          <el-input
            v-model="listQuery.username"
            placeholder="操作员账号"
            class="input-with-select"
            @keypress.enter.native="reloadList"
          />
        </el-col>
        <el-col :span="3">
          <el-input
            v-model="listQuery.name"
            placeholder="操作员姓名"
            class="input-with-select"
            @keypress.enter.native="reloadList"
          />
        </el-col>
        <el-col :span="3">
          <el-select
            v-model="listQuery.status"
            style="width:100%"
            placeholder="账号状态"
            clearable
            @change="reloadList"
          >

            <el-option
              label="启用"
              :value="1"
            />
            <el-option
              label="禁用"
              :value="2"
            />
          </el-select>
        </el-col>
        <el-col :span="3">
          <el-input
            v-model="listQuery.outlet_code"
            placeholder="网点代码"
            class="input-with-select"
            @keypress.enter.native="reloadList"
          />
        </el-col>
        <el-col :span="3">
          <el-input
            v-model="listQuery.outlet_name"
            placeholder="网点名称"
            class="input-with-select"
            @keypress.enter.native="reloadList"
          />
        </el-col>
        <el-col :span="6">
          <div>
            <el-button
              class="filter-item"
              type="primary"
              icon="el-icon-search"
              @click="reloadList"
            >搜索</el-button>
            <el-button
              class="filter-item"
              style="margin-left: 10px;"
              icon="el-icon-edit"
              type="primary"
              @click="addNews"
            >
              添加
            </el-button>
          </div>

        </el-col>

      </el-row>
    </div>
    <div style="padding:0 20px">

      <el-table
        ref="multipleTable"
        v-loading="listLoading"
        :data="list"
        height="calc(100vh - 200px)"
        style="width: 100%;"
        size="mini"
        border
        tooltip-effect="dark"
        :header-cell-style="{ background: '#eaf1fd', color: '#333' }"
      >
        <el-table-column
          label="操作员账号"
          width="200px"
          fixed
        >
          <template slot-scope="{ row }">
            <div>
              <span>{{ row.username }}</span>
            </div>
          </template>

        </el-table-column>
        <el-table-column
          label="操作员姓名"
          width="200px"
        >
          <template slot-scope="{ row }">
            <div>
              <span>{{ row.name }}</span>
            </div>
          </template>
        </el-table-column>
        <el-table-column
          label="所属网点代码"
          prop="outlet_code"
          width="200px"
        >
          <template slot-scope="{ row }">
            <div>
              <span>{{ row.outlet.code }}</span>
            </div>
          </template>
        </el-table-column>
        <el-table-column
          label="所属网点名称"
          prop="outlet_name"
          width="250px"
        >
          <template slot-scope="{ row }">
            <div>
              <span>{{ row.outlet.name }}</span>
            </div>
          </template>
        </el-table-column>
        <el-table-column
          label="状态"
          prop="outlet_name"
          width="100px"
        >
          <template slot-scope="{ row }">
            <div>
              <span v-if="row.status == 1" style="color:blue">启用</span>
              <span v-if="row.status == 2" style="color:red">禁用</span>

            </div>
          </template>
        </el-table-column>
        <el-table-column
          label="创建人"
          prop="admin.username"
          width="150px"
        />
        <el-table-column
          label="创建时间"
          prop="created"
          width="200px"
        />
        <!-- <el-table-column
          label="更新时间"
          prop="update_time"
          width="140px"
        /> -->
        <el-table-column
          label="操作"
          align="right"
          width="250"
          class-name="small-padding fixed-width"
          fixed="right"
        >
          <template slot-scope="{ row }">
            <el-button
              size="mini"
              type="primary"
              @click="edit(row)"
            >
              编辑
            </el-button>
            <el-button
              size="mini"
              type="primary"
              @click="editPass(row)"
            >
              修改密码
            </el-button>
            <el-button
              type="danger"
              @click="delet(row)"
            >
              删除
            </el-button>
          </template>
        </el-table-column>
      </el-table>
      <pagination
        v-show="total>0"
        :total="total"
        :page.sync="listQuery.page"
        :limit.sync="listQuery.limit"
        @pagination="getList"
      />
    </div>
    <Detial :detial="detial" :status="status" :visible="visible" @update="closeDraw" @reload="reloadList" />
    <el-dialog
      title="修改密码"
      :visible.sync="visiblePopover"
      width="400px"
    >
      <div style="padding:0 20px">
        <el-input
          v-model="password"
          placeholder="输入密码"
        />
      </div>

      <span slot="footer" class="dialog-footer">
        <el-button @click="visiblePopover = false">取 消</el-button>
        <el-button type="primary" @click="sumitPass">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { listAdminPda, delAdminPda, updatePassword } from '@/api/PDA/index'

import Pagination from '@/components/Pagination' // secondary package based on el-pagination
import Detial from './components/userDetial.vue'

export default {
  name: 'Dashboard',
  components: {
    Pagination,
    Detial
  },
  data() {
    return {
      data_arr: [],
      list: null,
      total: 0,
      listLoading: true,
      listQuery: {
        page: 1,
        limit: 20,
        username: '',
        name: '',
        status: '',
        outlet_code: '',
        outlet_name: ''
      },
      visible: false,
      status: 1,
      id: '',
      detial: {},
      visiblePopover: false,
      password: '',
      rowid: ''
    }
  },
  computed: {
  },
  created() {
    this.getList()
  },
  methods: {
    editPass(row) {
      this.visiblePopover = true
      this.rowid = row.id
      this.password = ''
    },
    closeDraw() {
      this.visible = false
    },
    addNews() {
      this.status = 1
      this.visible = true
    },
    edit(row) {
      this.detial = { ...row }
      this.status = 2
      this.visible = true
    },
    delet(row) {
      this.$confirm('此操作将永久删除该数据, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        delAdminPda({
          id: row.id
        }).then(res => {
          this.$message({
            type: 'success',
            message: '删除成功!'
          })
          this.getList()
        })
      }).catch(() => {

      })
    },
    sumitPass() {
      updatePassword({
        id: this.rowid,
        password: this.password
      }).then(response => {
        this.$message.success(response.msg)
        this.visiblePopover = false
        this.getList()
      })
    },
    reloadList() {
      this.listQuery.page = 1
      this.visible = false
      this.getList()
    },
    getList() {
      this.listLoading = true
      listAdminPda(this.listQuery).then(response => {
        this.list = response.data.data
        this.total = response.data.total
        this.listLoading = false
      })
    }
  }
}
</script>
<style scoped>
.filter-container{
  padding:20px 20px 10px;
  display: flex;
}

.upload-demo{
  margin: 20px 0 10px;
}
</style>
